package com.huluobo.a2303mdmdemo.demo

import android.util.Log
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.AccountCircle
import androidx.compose.material.icons.filled.Lock
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.text.input.VisualTransformation
import androidx.compose.ui.unit.dp

/**
 *  Created by LC on 2025/8/15.
 */

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun MyEdit() {
//    var name = ""

    var name by remember {
        //可变的状态
        mutableStateOf("")
    }

    var password by remember {
        mutableStateOf("")
    }

    var isShowPassword by remember {
        mutableStateOf(false)
    }

    Column(Modifier.padding(10.dp), verticalArrangement = Arrangement.spacedBy(10.dp)) {
        //带状态的控件
        TextField(value = name, onValueChange = {
            //当输入的值改变的时候
            name = it
            Log.e("TagA", "输入的值:$it")
        }, label = {//标签,类似hint属性,但是可以移动到输入框上方
            Text(text = "请输入用户名")
        }, trailingIcon = {//右侧图标
            Column {
                Text(text = "获取验证码", modifier = Modifier.clickable {
                    Log.e("TagA", "获取验证码")
                })
                Text(text = "倒计时10S")
            }
        }, leadingIcon = {
            Icon(imageVector = Icons.Default.AccountCircle, contentDescription = "")
        }, modifier = Modifier.fillMaxWidth())

        OutlinedTextField(value = name, onValueChange = { name = it }, label = {
            Text(text = "请输入用户名")
        }, leadingIcon = {
            Icon(imageVector = Icons.Default.AccountCircle, contentDescription = "")
        }, trailingIcon = {

        }, modifier = Modifier.fillMaxWidth())

        OutlinedTextField(value = password, onValueChange = { password = it }, label = {
            Text(text = "请输入密码")
        }, leadingIcon = {
            Icon(imageVector = Icons.Default.AccountCircle, contentDescription = "")
        }, trailingIcon = {
            Icon(imageVector = Icons.Default.Lock, contentDescription = "", modifier = Modifier.clickable {
                isShowPassword = !isShowPassword
            })
        }, modifier = Modifier.fillMaxWidth(),
            //是否显示密文 visualTransformation 视觉转换
            visualTransformation = if (isShowPassword) VisualTransformation.None else PasswordVisualTransformation()
        )

    }
}